#include <bits/stdc++.h>

using namespace std;

int main()
{
    unordered_set<int> s;
    size_t T;
    cin >> T;
    int ans1 = -1, ans2 = -1;
    bool found = false;
    for (size_t edgeNum = 1; edgeNum <= T; ++edgeNum)
    {
        int u, v;
        cin >> u >> v;
        s.emplace(u);
        s.emplace(v);
        // ! not right! 
        if (!found && s.size() <= edgeNum)
        {
            ans1 = min(u, v);
            ans2 = max(u, v);
            found = true;
        }
    }
    cout << ans1 << " " << ans2 << endl;

    // system("pause");
    return 0;
}
